/*************************************************
Author: byron
Date: 12/07/2012
Description:
Notes: 
*************************************************/

#ifndef __CWorldBossMgr_h__
#define __CWorldBossMgr_h__

#include "commclass.h"
#include "CWorldBossCfg.h"
#include "CWorldBossData.h"

class CPlayerBaseInfo;
class CPlayerDetailInfo;
class CPlayerCacheData;
class CPlayerOnlineData;
class MsgReqWorldBoss;
class MsgAnsWorldBoss;
class CDropItem;
class CBattleRole;
class CActCfgData;
class MsgReqGMPlayer;
class MsgAnsGMPlayer;
class MsgWorldBossMonster;

class CWorldBossCmdData
{
public:
    CWorldBossCmdData()
    {
        Clear();
    }

    void Clear()
    {
        _bActClose = false;
        _bFiftyKill = false;
        _bDeadKill = false;
        _iFiftySilver = 0;
        _iFiftyRepu = 0;
        _iDeadSilver = 0;
        _iDeadRepu = 0;
    }

    virtual ~CWorldBossCmdData()
    {
    }

    bool GetActClose() const {return _bActClose;}
    bool GetFiftyKill() const {return _bFiftyKill;}
    bool GetDeadKill() const {return _bDeadKill;}
    int GetFiftySilver() const {return _iFiftySilver;}
    int GetFiftyRepu() const {return _iFiftyRepu;}
    int GetDeadSilver() const {return _iDeadSilver;}
    int GetDeadRepu() const {return _iDeadRepu;}

    void SetActClose(bool bVal) {_bActClose = bVal;}
    void SetFiftyKill(bool bVal) {_bFiftyKill = bVal;}
    void SetDeadKill(bool bVal) {_bDeadKill = bVal;}
    void SetFiftySilver(int iVal) {_iFiftySilver = iVal;}
    void SetFiftyRepu(int iVal) {_iFiftyRepu = iVal;}
    void SetDeadSilver(int iVal) {_iDeadSilver = iVal;}
    void SetDeadRepu(int iVal) {_iDeadRepu = iVal;}

private: 
    bool    _bActClose;
    bool    _bFiftyKill;
    bool    _bDeadKill;
    int     _iFiftySilver;
    int     _iFiftyRepu;
    int     _iDeadSilver;
    int     _iDeadRepu;
};

class CWorldBossMgr
{
public:
    enum CMD_WORLD_BOSS_SUB_TAG
    {
        CMD_WORLD_BOSS_SUB_BUFF = 1,            //购买梅林的祝福状态
        CMD_WORLD_BOSS_SUB_REVIVE = 2,          //金币复活
        CMD_WORLD_BOSS_SUB_BATTLE = 3,          //进入战斗
        CMD_WORLD_BOSS_SUB_INSPIRE = 4,         //施加鼓舞状态
        CMD_WORLD_BOSS_SUB_DEAD = 5,            //角色死亡

        //怪物血量+攻击伤害榜+主角名次及攻击伤害
        CMD_WORLD_BOSS_SUB_ATK_RANK = 6,
    };

    enum ENUM_WORLD_BOSS_MACRO_TAG
    {
        WORLD_BOSS_INSPIRE_TRIGGER = 50,        //千分比 鼓舞状态触发条件
        WORLD_BOSS_MERLIN_GOLD_INIT = 2,       //梅林祝福金币初始价格
        WORLD_BOSS_MERLIN_GOLD_ADD = 0,         //梅林祝福金币价格递增量 20130701策划暂时不要求递增
        WORLD_BOSS_MERLIN_GOLD_MAX = 100,       //梅林祝福金币价格上限
        WORLD_BOSS_DEAD_GOLD_INIT = 5,         //死亡复活金币初始价格
        WORLD_BOSS_DEAD_GOLD_ADD = 0,          //死亡复活金币价格递增量
        WORLD_BOSS_DEAD_GOLD_MAX = 100,         //死亡复活金币价格上限
        WORLD_BOSS_DEAD_WAIT_TIME = 30,         //死亡冷却时长
        WORLD_BOSS_FIGHT_WAIT_TIME = 10,        //战斗冷却时长
        WORLD_BOSS_NOTIFY_WAIT_TIME = 5,        //下发怪物血量及排名榜间隔
        WORLD_BOSS_MONSTER_BORN_TIME = 180,     //活动开启后怪物出生时长
    };

    CWorldBossMgr()
    {
    }

    virtual ~CWorldBossMgr()
    {
    }
   
    int ActOpen(CActCfgData& stActCfgData);
    int ActClose(CActCfgData& stActCfgData);

    int LoadConfig(const char* szCfgPath);

    bool IsMapIDNeedUpdateDB(const unsigned int uiMapID);

    int EnterScene(const unsigned int uiMapID, unsigned int uiGID);
    int LeaveScene();

    unsigned int GetWorldBossMapID();

    int InitPlayerData(CPlayerCacheData& stPlayerCache);

    int GetReviveGold(CPlayerCacheData& stPlayerCache);

    int GetMerlinGold(CPlayerCacheData& stPlayerCache);

    int BuyMerlin(CPlayerBaseInfo& stPlayerBase,
            CPlayerCacheData& stPlayerCache, MsgAnsWorldBoss& stAns);

    int AddInspire(CPlayerCacheData& stPlayerCache);

    int DeadRevive(CPlayerBaseInfo& stPlayerBase,
            CPlayerCacheData& stPlayerCache, MsgAnsWorldBoss& stAns);

    int WorldBossBattle(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerCacheData& stPlayerCache,
            MsgReqWorldBoss& stReq, MsgAnsWorldBoss& stAns,
            CWorldBossCmdData& stCmdData);

    int ReviseBeforeBattle(int iBossBattleID);

    int DealMonsterAfterBattle(CPlayerBaseInfo& stPlayerBase,
            CBattleRole& stBattleObj, CWorldBossCmdData& stCmdData);

    int DealPlayerAfterBattle(CPlayerBaseInfo& stPlayerBase,
            CPlayerOnlineData& stPlayerOnline, CPlayerCacheData& stPlayerCache,
            MsgAnsWorldBoss& stAns, int iBattleResult,
            CWorldBossCmdData& stCmdData);

    int GMDealWorldBoss(CPlayerDetailInfo& stPlayerDetail,
            MsgReqGMPlayer& stReq, MsgAnsGMPlayer& stAns);

    void WorldBossNotify();

    void WorldBossNotify(unsigned int uiGID, int iSubCmd,
            bool bNotifySelf);

    void WorldBossNotify(unsigned int uiGID, int iSubCmd,
            MsgAnsWorldBoss& stAns);

    void WorldBossSceneNotify();

    void WorldBossNotifyTips(int iTipType);

    void WorldBossNotifyTips(int iTipType, int iSilver, int iRepu,
            CPlayerBaseInfo& stPlayerBase);

    void GetWorldBossKillerInfo(MsgAnsWorldBoss& stAns);

    void GetWorldBossMonster(MsgAnsWorldBoss& stAns);

    void GetWorldBossRole(CPlayerCacheData& stPlayerCache,
        MsgAnsWorldBoss& stAns);

    void GetWorldBossAtkRank(MsgAnsWorldBoss& stAns);

    int GetWorldBossSceneInfo(CPlayerCacheData& stPlayerCache,
        MsgAnsWorldBoss& stAns);

    int WorldBossFinishReward ();

    int WorldBossRewardItem(unsigned int uiGID, int iRepu, int iExp,
        int iContri, int iSilver, CDropItem& stDropItem);

    int WorldBossRoleReward(CPlayerBaseInfo& stPlayerBase,
            MsgAnsWorldBoss& stAns, CWorldBossCmdData& stCmdData);

    void InitWorldBossCfg() {_stWorldBossCfg.InitWorldBossCfg();}

    int AddAttackConfig(CWorldBossCfgAttack& stCfgData)
    {
        return _stWorldBossCfg.AddAttackConfig(stCfgData);
    }

    int FindAttackConfig(int iAttackValue)
    {
        return _stWorldBossCfg.FindAttackConfig(iAttackValue);
    }

    CWorldBossCfgAttack& GetAttackConfig(int iIndex)
    {
        return _stWorldBossCfg.GetAttackConfig(iIndex);
    }

    int AddRewardConfig(CWorldBossCfgReward& stCfgData)
    {
        return _stWorldBossCfg.AddRewardConfig(stCfgData);
    }

    int FindRewardConfig(int iLevel)
    {
        return _stWorldBossCfg.FindRewardConfig(iLevel);
    }

    CWorldBossCfgReward& GetRewardConfig(int iIndex)
    {
        return _stWorldBossCfg.GetRewardConfig(iIndex);
    }

    int GetRewardConfig(unsigned short usBossLevel, CWorldBossCfgReward& stCfgData)
    {
        int iIndex = _stWorldBossCfg.FindRewardConfig(usBossLevel);
        if (iIndex < 0)
        {
            CT_WARNING(("reward level(%d) config empty", usBossLevel));
            return RET_SYS_ERROR;
        }

        stCfgData = _stWorldBossCfg.GetRewardConfig(iIndex);
        return 0;
    }

private: 
    bool    _bFifty;
    bool    _bKill;
    CWorldBossCfg   _stWorldBossCfg;
    CWorldBossMonster _stWorldBossMonster;
};

#endif //__CWorldBossMgr_h__

